package com.kylefu.design.pattern;

/**
 * 单例模式，spring容器加载bean都是单例
 */
public class Singleton {

  private final static Object obj = new Object();
  private static Singleton instance;

  /**
   * 双重校验
   */
  public Singleton getInstance(){
    if(instance == null){
      synchronized (obj){
        if(instance == null){
          instance = new Singleton();
        }
      }
    }
    return instance;
  }

}
